package worldinruin.gui.imp.gameview;
import javax.swing.GroupLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle;

import worldinruin.core.ISoldier;
import worldinruin.core.imp.battle.Dice;
import worldinruin.resources.IconMap;
import worldinruin.utils.ResizableLabel;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class BattleUnitComponent extends JPanel {
	private ResizableLabel unitLabel;
	private DiceLabel diceLabel; 
	private JLabel unitAttack;
	private ISoldier soldier;
	private int amount;
	
	/**
	 * Creates a component on battle troop panel with the soldier and amount.
	 * @param soldier Soldier type.
	 * @param amount Amount.
	 */
	public BattleUnitComponent(ISoldier soldier, int amount) {
		this.soldier = soldier;
		this.amount = amount;
		initGUI();
		setupGUI();
	}

	/**
	 * Setup GUI.
	 */
	private void setupGUI() {
		unitLabel.setText(amount + "");
		unitAttack.setText(soldier.getAttack() + "");
		
		revalidate();
		repaint();
	}

	/**
	 * Initiate GUI.
	 */
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			{
				unitLabel = new ResizableLabel(IconMap.getInstance().getIcon(soldier.getSoldierType()).getImage());
				unitLabel.setText("Unit");
			}
			{
				diceLabel = new DiceLabel(new Dice());
				diceLabel.setText("Dice");
			}
			{
				unitAttack = new JLabel();
				unitAttack.setText("attack");
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(21, 21)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(unitLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
				    .addComponent(diceLabel, GroupLayout.Alignment.BASELINE, 0, 70, Short.MAX_VALUE)
				    .addComponent(unitAttack, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(27, 27));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(18, 18)
				.addComponent(unitLabel, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE)
				.addGap(41)
				.addComponent(diceLabel, 0, 70, Short.MAX_VALUE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addComponent(unitAttack, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(21, 21));
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

}
